<?php 
include('./fun.php');
$conn=my_sql($cfg);
$re=adm_login();
if($re['err']=='no_login'){no_login();}
$adm=$re['adm'];
$sql='select * from '.$cfg['e'].'shop ';
$state=g('state');
if($state!='stop'){$sql.=' where state=1 ';}else{$sql.=' where state=99 ';}
$key=g('key');
if($key){
$sql.=' and temp like "%'.a($key).'%" ';
}


$page=g('page');
if(!$page){$page=1;}
$page_num=20;
$start=($page-1)*$page_num;
$sql.=' order by id desc limit '.$start.','.$page_num;
$l=db($sql);



?>
<style>
xl{float:left;width:50%;padding-right:10px;margin-top:10px}
xl handle{float:left;width:100%;height:40px;line-height:30px;font-size:18px;font-weight:bold;}
</style>

<hh><b>门店列表</b></hh>
<mm>
<index>

</index>

<?php if($l){
echo  '<table>';
th(['id','logo','名称','创建时间','地区','地址','联系人','联系电话','活动数','订单数','余额','绑定','状态','操作']);
foreach($l as $v){
echo '<tr>';
echo '<td>'.$v['id'].'</td>';
echo '<td><img src="'.$v['logo'].'" style="width:30px;height:30px;border-radius:50%;"></td>';
echo '<td>'.base64($v['shop_name']).'</td>';

echo '<td>'.date('Y-m-d H:i',$v['date']).'</td>';
echo '<td>'.$v['pro'].' '.$v['city'].' '.$v['dist'].'</td>';
echo '<td>'.$v['addr'].'</td>';
echo '<td>'.$v['name'].'</td>';
echo '<td>'.$v['phone'].'</td>';
echo '<td>'.$v['hd_num'].'</td>';
echo '<td>'.$v['order_num'].'</td>';
echo '<td>'.$v['balance'].'</td>';
echo '<td>'.($v['wx_name']?'是':'否').'</td>';
echo '<td>'.($v['state']==1?'正常':'停用').'</td>';
echo '<td>
<a href="?url=shop_info&left_c=shop_list&id='.$v['id'].'">详情</a>
</td>';
echo '</tr>';
}



echo '</table>';
page();
}else{no_data('没有找到门店');}?>


</mm>



<script>
function val_change(o){
var c=o.attr('c');
var val=o.val();if(!val){msg('请输入内容');return;}
var data={[c]:val}
post('shop_edit',data,'<?php echo $l['id']?>',function(res){
    msg('修改成功');
});

}

function select_logo(o){
var val=o.attr('img_480');
var data={'logo':val}
post('shop_edit',data,'<?php echo $l['id']?>',function(res){
 msg('修改成功');
 main_load();
});
}

function state(o){
var c=o.attr('c');
var id=o.attr('i');
var val=o.attr('val');
if(val!=1){val=0;}
var data={[c]:val}
post('shop_adm_edit',data,id,function(res){
    msg('操作成功');
    main_load();
});
}

function del(o){
var id=o.attr('i');
var c=o.attr('c');
if(c=='adm'){var text='是否删除门店管理员';
var data={shop_id:0,shop_state:0}
}else{var text='是否删除门店雇员';var data={is_emp:0,emp_state:0}}
if(!confirm(text+'？删除不会删除用户信息')){return;}

post('shop_adm_edit',data,id,function(res){
    msg('操作成功');
    main_load();
});
}

function add_box(o){
var c=o.attr('c');
window.add_c=c;
right({title:'添加门店管理人员',url:'select_user.php',width:'500px'})
}
function user_add(o){
var id=o.attr('i');
if(window.add_c=='adm'){
var data={shop_id:'<?php echo $l['id']?>',shop_state:1}
}else{
var data={is_emp:'<?php echo $l['id']?>',emp_state:1}
}
post('shop_adm_edit',data,id,function(res){
    msg('操作成功');
    main_load();
});
}

function get_qr(){
var data={page:'pages/shop/edit'}
post('get_qr_data',data,1,function(res){
    if(res.qr){
    win({title:'二维码',html:'<img src="'+res.qr+'">',width:400});
    }
    
});
}


</script>